﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using LowLevelGraphics;
using LowLevelGraphics.Filter;
using LowLevelGraphics.Forms;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// This is used to perform an edge filter command
    /// </summary>
    public class ActionEdge : AbstractCommand
    {
        protected PictureBox m_PictureBox = null;
        private short m_shType = -1;

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionEdge"/> class.
        /// </summary>
        /// <param name="_shType">Type of the _SH.</param>
        public ActionEdge(short _shType)
        {
            m_shType = _shType;
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            FormParameter parameter = new FormParameter();
            if (parameter.ShowDialog() == DialogResult.OK)
            {
                Bitmap bitmap = (Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage;
                UnsafeBitmap unsafeBitmap = new EdgeDetectConvolution(m_shType, (byte)parameter.nValue).Execute(bitmap);
                unsafeBitmap.Dispose();
            }
        }    
    }
}
